{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Confusion Matrix Analysis and Viewing Misclassifications"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_train shape: (60000, 28, 28, 1)\n",
      "60000 train samples\n",
      "10000 test samples\n",
      "Number of Classes: 10\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "conv2d_3 (Conv2D)            (None, 26, 26, 32)        320       \n",
      "_________________________________________________________________\n",
      "conv2d_4 (Conv2D)            (None, 24, 24, 64)        18496     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_2 (MaxPooling2 (None, 12, 12, 64)        0         \n",
      "_________________________________________________________________\n",
      "dropout_3 (Dropout)          (None, 12, 12, 64)        0         \n",
      "_________________________________________________________________\n",
      "flatten_2 (Flatten)          (None, 9216)              0         \n",
      "_________________________________________________________________\n",
      "dense_3 (Dense)              (None, 128)               1179776   \n",
      "_________________________________________________________________\n",
      "dropout_4 (Dropout)          (None, 128)               0         \n",
      "_________________________________________________________________\n",
      "dense_4 (Dense)              (None, 10)                1290      \n",
      "=================================================================\n",
      "Total params: 1,199,882\n",
      "Trainable params: 1,199,882\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "None\n",
      "Train on 60000 samples, validate on 10000 samples\n",
      "Epoch 1/1\n",
      "60000/60000 [==============================] - 147s 2ms/step - loss: 0.2660 - acc: 0.9171 - val_loss: 0.0604 - val_acc: 0.9811\n",
      "Test loss: 0.060351789912581444\n",
      "Test accuracy: 0.9811\n"
     ]
    }
   ],
   "source": [
    "from keras.datasets import mnist\n",
    "from keras.utils import np_utils\n",
    "import keras\n",
    "from keras.datasets import mnist\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Dropout, Flatten\n",
    "from keras.layers import Conv2D, MaxPooling2D\n",
    "from keras import backend as K\n",
    "\n",
    "# Training Parameters\n",
    "batch_size = 128\n",
    "epochs = 1\n",
    "\n",
    "# loads the MNIST dataset\n",
    "(x_train, y_train), (x_test, y_test)  = mnist.load_data()\n",
    "\n",
    "# Lets store the number of rows and columns\n",
    "img_rows = x_train[0].shape[0]\n",
    "img_cols = x_train[1].shape[0]\n",
    "\n",
    "# Getting our date in the right 'shape' needed for Keras\n",
    "# We need to add a 4th dimenion to our date thereby changing our\n",
    "# Our original image shape of (60000,28,28) to (60000,28,28,1)\n",
    "x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)\n",
    "x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)\n",
    "\n",
    "# store the shape of a single image \n",
    "input_shape = (img_rows, img_cols, 1)\n",
    "\n",
    "# change our image type to float32 data type\n",
    "x_train = x_train.astype('float32')\n",
    "x_test = x_test.astype('float32')\n",
    "\n",
    "# Normalize our data by changing the range from (0 to 255) to (0 to 1)\n",
    "x_train /= 255\n",
    "x_test /= 255\n",
    "\n",
    "print('x_train shape:', x_train.shape)\n",
    "print(x_train.shape[0], 'train samples')\n",
    "print(x_test.shape[0], 'test samples')\n",
    "\n",
    "# Now we one hot encode outputs\n",
    "y_train = np_utils.to_categorical(y_train)\n",
    "y_test = np_utils.to_categorical(y_test)\n",
    "\n",
    "# Let's count the number columns in our hot encoded matrix \n",
    "print (\"Number of Classes: \" + str(y_test.shape[1]))\n",
    "\n",
    "num_classes = y_test.shape[1]\n",
    "num_pixels = x_train.shape[1] * x_train.shape[2]\n",
    "\n",
    "# create model\n",
    "model = Sequential()\n",
    "\n",
    "model.add(Conv2D(32, kernel_size=(3, 3),\n",
    "                 activation='relu',\n",
    "                 input_shape=input_shape))\n",
    "model.add(Conv2D(64, (3, 3), activation='relu'))\n",
    "model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "model.add(Dropout(0.25))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(128, activation='relu'))\n",
    "model.add(Dropout(0.5))\n",
    "model.add(Dense(num_classes, activation='softmax'))\n",
    "\n",
    "model.compile(loss = 'categorical_crossentropy',\n",
    "              optimizer = keras.optimizers.Adadelta(),\n",
    "              metrics = ['accuracy'])\n",
    "\n",
    "print(model.summary())\n",
    "\n",
    "\n",
    "history = model.fit(x_train, y_train,\n",
    "          batch_size=batch_size,\n",
    "          epochs=epochs,\n",
    "          verbose=1,\n",
    "          validation_data=(x_test, y_test))\n",
    "\n",
    "score = model.evaluate(x_test, y_test, verbose=0)\n",
    "print('Test loss:', score[0])\n",
    "print('Test accuracy:', score[1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Let's save our history file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle \n",
    "\n",
    "pickle_out = open(\"MNIST_history.pickle\",\"wb\")\n",
    "pickle.dump(history.history, pickle_out)\n",
    "pickle_out.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Loading out saved history is as simple as these two lines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'val_loss': [0.07168159085139632], 'val_acc': [0.9774], 'loss': [0.26640635084311165], 'acc': [0.9185166666348775]}\n"
     ]
    }
   ],
   "source": [
    "pickle_in = open(\"MNIST_history.pickle\",\"rb\")\n",
    "saved_history = pickle.load(pickle_in)\n",
    "print(saved_history)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCB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/96M2/cr33nuP3r17F7SIWPsjid69e6c6UnUhMSuEY6+AZx+g69a/tunXuohYQ9L+XLiQmBVCj4/DkRM55NX/LnQkTbplwYuFDsHaORcSs0L55MkcUjMbvtNz52XRvxc6sp38aOGqVhlnzJgxzJ8/f6e2W2+9lcsuu6zRft27dwfgtdde48wzz2xwn9GjRzf50PGtt97K5s0fTpDx2c9+lrfffrs5oTfoqaeeYsCAAZSXl1NeXk737t35h3/4B8rLy7ngggtaNNa2bdu48cYbd7m9tLQ0VaxZcyExK4T3N8Hcb7LisCvgO+/svIy5ptDRZWLixInMnDlzp7aZM2cyceLEZvU/+OCDefjh3Z9ir34hmTt3Lvvtt99ujzdv3jxuuukmli1bxrJly6isrOT+++9n2bJl3HPPPS0aq6lC0t65kJgVwpyroLSSP3+889yEeOaZZzJnzhzef/99ANauXctrr73GyJEjqa2t5YQTTqCiooIjjjiCWbNmfaT/2rVrOfzwwwHYsmULEyZMYPDgwZx++uls2bJlx36XXXYZlZWVDB06lOuvvx6A2267jddee40xY8YwZswYIDd10oYNGwC4+eabOfzwwzn88MO59dZbd3zf4MGD+eIXv8jQoUMZO3bsTt+zcOFCTjxxlzeeUldXx5VXXsnw4cM55phjuPvuuwFYt24dn/nMZygvL+fwww/nd7/7HVOmTGHjxo0tOprZsGED48ePp6ysjE9/+tM8/3zukbonnniCI488kvLycioqKti0aVOD39ma2sUUKWadyjP3w2tPwxefgN8tLkgI/afMyWT/tTf+4y637b///gwfPpwFCxYwYcIEZs6cyVlnnYUkSkpKePTRR9l3333ZsGEDRx99NOPHj9/lReCf/OQnfOxjH2PFihVUV1dTUVGxY9t3v/td9t9/fz744ANOOOEEqqur+drXvsbNN9/MokWL6NOnz05jLV26lBkzZvCHP/yBiGDEiBEcd9xx9OrVi1WrVvHggw9y1113cdZZZ/HII49w3nnnsWHDBoqLi+nZs+cu8502bRoHHnggf/zjH9mwYQMnnXQSY8eO5cEHH+Rzn/scV199NR988AFbtmxh+PDh3H333SxbtqxZf88A//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yvaM9Me2nvDuHtn6yfcfT1d/Z9fTn9XX/z4qmd9ruO03/rieJvffemx49etC9e3defPFF7rvvPiorcw9Q//CHP2T//fenrq6OMWPGcO655zJkyBCKioro1q0bPXr04J133uGkk07i5ptv5sorr+Shhx5iypQp7L333pSUlNCjRw+KioooLi5m6dKlzJ49m5tuuonHHnuM22+/ndLSUmbNmsWzzz5LRUXFjnHz5X/fdnfccQfdu3dn+fLlLF++nM9+9rOsWrWKn//851x99dWcffbZbN26lYhg1qxZDBw4kAULFrBx40a2bdvWrp9uLykpYdiwYbvVN8trJIuBQcldVl2BCcDs/B0kDQPuBMZHxBt57b0k7Z2s9wGOBV6I3Hwui4Dt79u8EPjoG3DMrMP4xCc+saOIADz44INUVFRQUVHBihUrGpwGfp999uGUU04Bdp7evb4zzjjjI/s8+eSTO6Y3OfLIIxk6dGizY33yySd3TF8/dOhQDj74YFavXs2nP/1pbrjhBr7//e/z6quvUlJSQllZGY899hhTpkzhqaeeavTdJR1dZkckEVEn6XJgPlAETI+I5ZKmAksiYjbwA6A78ItkMrJXkju0BgN3StpGrtjdGBHbf5quBmZKuoHcXV8/zSoHsz1WM44ceH8TTBuTm/a+/JzMQunW7cP3sqxatYof/ehH/PGPf2S//fbjvPPOa3Aa+K5dP7zrv6ioaJez5m6fBr6xfVrD+eefzzHHHMOcOXMYN24c06dPZ9SoUSxZsoS5c+dy/fXXs3jxYq699trMYiikTK+RRMRcYG69tuvy1ht8T2VE/A44Yhfb1pC7I8zMspS8DjjLIlLfu+++S48ePdh3331Zv3498+fPZ9y4ca36HcceeywPPfQQI0eO5LnnnmvyxVf5tk/dPmrUKFasWMH69esZOHAga9asYeDAgVxxxRW8/PLLVFdX84lPfII+ffpw/vnn06VLFx555JFWzaM9aRcX282sncl/HXAbqqioYMiQIRx22GEceuihO00D31q++tWvcsEFFzBkyJAdy65OO5188skUFxcDuSIyffp0Lr30Uo444giKi4u555576Nq1Kw888AAPPvggxcXFHHzwwXznO9/Z8S72vfbai6Ki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wS+CX2ye0NCsUH5GYZSN2sd4SW/PWt79GAOAfgdvJHb0sluRrnVZQLiRm2Tg778/fJ+u/IzfzMcC5fDgV/kLgMgBJRZJ67mrQZIbkQyJiEXA10JPcNORmBePfZMx23z6S8meofSxvKvBekqrJHVVMTNq+CsyQ9A3gTT6cCfYKYJqkS8gdeVxG7m2QDSkC7kuKjYDbIuLtVsvIbDf4GolZK0uukVRGxIZCx2LWFnxqy8zMUvERiZmZpeIjEjMzS8WFxMzMUnEhMTOzVFxIzMwsFRcSMzNLxYXEzMxS+f+oM1e5gk7CIwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plotting our loss charts\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "history_dict = history.history\n",
    "\n",
    "loss_values = history_dict['loss']\n",
    "val_loss_values = history_dict['val_loss']\n",
    "epochs = range(1, len(loss_values) + 1)\n",
    "\n",
    "line1 = plt.plot(epochs, val_loss_values, label='Validation/Test Loss')\n",
    "line2 = plt.plot(epochs, loss_values, label='Training Loss')\n",
    "plt.setp(line1, linewidth=2.0, marker = '+', markersize=10.0)\n",
    "plt.setp(line2, linewidth=2.0, marker = '4', markersize=10.0)\n",
    "plt.xlabel('Epochs') \n",
    "plt.ylabel('Loss')\n",
    "plt.grid(True)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xt8FdW5//HPQwC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HpOyUKkiv3hpQ9oN2n+US+AdpPmk//FAVbl72JV/i627Sn/kMCDS9ZXSWw5OTksWrToqLIHHniAcePGlXleamoqAFu2bGHEiBEl1snOzg79YOwDDzzA/v374/sXXnghu3btKk/oJXrjjTdo3749Xbt2pWvXrqSmpnL66afTtWtXrrjiimO61pEjR5gyZUqZdd555x3MjJdffrnCMdda7l4nXj169PDaaOnSpckOodrVxza3vfX/ubv7mjVrKnV+Zf3pT3/yMWPGHFXWq1cv//vf/17meSeccELotfv37+9vv/12fH/Pnj3fqNO2bVv//PPPyxltuDvvvNPnzJlTagzH4tChQ96sWbMy69x0003et29fv+qqq0o8XlKbKxpLFEr690fs7tTQ37HqWYjUIyNGjGD+/Pl89dVXAGzatIktW7bQr18/CgoKGDBgAN27d+fMM8/khRde+Mb5mzZtonPnzgAcOHCAkSNH0rFjR4YOHcqBAwfi9caNG0f//v3p1KkTv/rVrwB46KGH2LJlCzk5OeTk5ACxZXq2b98OwP3330/nzp3p3LkzDzzwQPz9OnbsyDXXXEOnTp0YOHDgUe+zZMkSfvjDH5ba3sLCQm666SZ69uxJZmYmjz32GACbN2+mb9++dO3alc6dO/Paa68xadIk9u7dW2qv5MiRIzz77LM8+eSTLFy4MP49BHj88cfJzMzknHPO4corrwTg008/ZciQIWRmZtKlSxfefPNNNmzYQNeuXePnTZkyhd/+9rcA9O3blxtvvJGsrCymTp3KCy+8QK9evejWrRsDBw7ks88+A2J3XP3kJz8hMzOTzMxM5s6dy/Tp05k4cWL8uo888gg333xzqd+Xikj2ch8i9VbR8FRV19805d9KPXbSSSfRs2dPFi5cyJAhQ5g1axaXXHIJZkaTJk14/vnnOfHEE9m+fTtnn302F110UakTo4888gjf+ta3WLt2LatWraJ79+7xY3fffTeNGjXiW9/6FgMGDGDVqlVcf/313H///SxdupRWrVodda0VK1bw+OOP8+abb+Lu9OrVi/79+9OiRQvWr19Pbm4uf/7zn7nkkkt49tlnufzyy9m+fTuNGjWiWbNmpbZ3+vTpnHzyybz11l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DR37wTsAoYH5ZOAbsF1fhZV40TKQ5/gFgkRLPyWWkL5JuA8d98YrGf1qbu3NLPtwHfc/VBQvtXdW5nZ50C6u3+ZcI12xJ5r0SHYvxVo5O6/NbMXgQJgLjC3aJFFkWRQz0KkcryU7WPxZcJ20RL1AP8GTCPWC3nbzDTHKEmjZCFSOZcmfH092H6N2Iq7AKP5epn1JcA4ADNLMbNmpV00WJm3jbsvBW4FmhFb4lokKfSXiki4480scWXUFxOWmW5hZquI9Q5GBWXXAY+b2c3A53y9AukNwHQz+ymxHsQ4Yk8FLEkK8F9BQjHgIXffVWUtEjlGmrMQqaBgziLL3bcnOxaRqGkYSkREQqlnISIiodSzEBGRUEoWIiISSslCRERCKVmIiEgoJQsREQmlZCEiIqH+P7vRvIjfpyyHAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plotting our accuracy charts\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "history_dict = history.history\n",
    "\n",
    "acc_values = history_dict['acc']\n",
    "val_acc_values = history_dict['val_acc']\n",
    "epochs = range(1, len(loss_values) + 1)\n",
    "\n",
    "line1 = plt.plot(epochs, val_acc_values, label='Validation/Test Accuracy')\n",
    "line2 = plt.plot(epochs, acc_values, label='Training Accuracy')\n",
    "plt.setp(line1, linewidth=2.0, marker = '+', markersize=10.0)\n",
    "plt.setp(line2, linewidth=2.0, marker = '4', markersize=10.0)\n",
    "plt.xlabel('Epochs') \n",
    "plt.ylabel('Accuracy')\n",
    "plt.grid(True)\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Now let's display our Confusion Matrix and Classification Report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.97      0.99      0.98       980\n",
      "           1       0.98      1.00      0.99      1135\n",
      "           2       0.99      0.97      0.98      1032\n",
      "           3       0.98      0.98      0.98      1010\n",
      "           4       0.99      0.98      0.98       982\n",
      "           5       0.98      0.98      0.98       892\n",
      "           6       0.99      0.98      0.98       958\n",
      "           7       0.98      0.97      0.98      1028\n",
      "           8       0.98      0.97      0.98       974\n",
      "           9       0.97      0.98      0.97      1009\n",
      "\n",
      "   micro avg       0.98      0.98      0.98     10000\n",
      "   macro avg       0.98      0.98      0.98     10000\n",
      "weighted avg       0.98      0.98      0.98     10000\n",
      "\n",
      "[[ 974    0    0    0    0    1    1    1    3    0]\n",
      " [   0 1130    1    2    0    0    1    0    1    0]\n",
      " [   5    5 1002    4    3    0    0    9    3    1]\n",
      " [   1    0    2  994    0    5    0    5    1    2]\n",
      " [   1    1    0    0  963    0    6    0    2    9]\n",
      " [   3    0    0    6    0  878    2    1    2    0]\n",
      " [   6    3    0    0    2    4  941    0    2    0]\n",
      " [   1    4   10    2    2    0    0  999    1    9]\n",
      " [   7    0    1    2    4    2    2    2  945    9]\n",
      " [   5    6    0    3    3    2    0    3    2  985]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import classification_report,confusion_matrix\n",
    "import numpy as np\n",
    "\n",
    "y_pred = model.predict_classes(x_test)\n",
    "\n",
    "print(classification_report(np.argmax(y_test,axis=1), y_pred))\n",
    "print(confusion_matrix(np.argmax(y_test,axis=1), y_pred))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Displaying our misclassified data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indices of misclassifed data are: \n",
      "\n",
      "(array([ 247,  259,  290,  320,  321,  445,  449,  582,  659,  684,  691,\n",
      "        717,  720,  740,  844,  846,  924,  939,  947,  965, 1014, 1039,\n",
      "       1062, 1112, 1181, 1182, 1202, 1226, 1232, 1242, 1247, 1260, 1290,\n",
      "       1299, 1319, 1326, 1393, 1402, 1500, 1522, 1530, 1549, 1553, 1621,\n",
      "       1678, 1681, 1686, 1709, 1717, 1754, 1790, 1878, 1901, 2035, 2043,\n",
      "       2044, 2053, 2070, 2098, 2109, 2118, 2129, 2130, 2135, 2182, 2185,\n",
      "       2189, 2272, 2280, 2293, 2369, 2387, 2406, 2454, 2462, 2488, 2597,\n",
      "       2607, 2654, 2771, 2780, 2810, 2896, 2921, 3060, 3073, 3206, 3289,\n",
      "       3316, 3333, 3422, 3475, 3503, 3520, 3558, 3597, 3662, 3726, 3730,\n",
      "       3767, 3778, 3780, 3796, 3808, 3811, 3836, 3850, 3853, 3906, 3941,\n",
      "       3951, 4007, 4075, 4078, 4102, 4176, 4199, 4205, 4224, 4238, 4248,\n",
      "       4256, 4289, 4360, 4500, 4536, 4571, 4601, 4639, 4740, 4751, 4761,\n",
      "       4783, 4807, 4808, 4874, 4876, 4956, 5067, 5278, 5288, 5331, 5600,\n",
      "       5642, 5734, 5887, 5888, 5937, 5955, 5973, 6004, 6035, 6091, 6505,\n",
      "       6555, 6576, 6597, 6651, 6740, 6796, 6847, 7121, 7432, 7434, 7886,\n",
      "       8059, 8091, 8094, 8095, 8408, 8527, 9009, 9015, 9019, 9024, 9280,\n",
      "       9634, 9642, 9664, 9716, 9726, 9729, 9770, 9792, 9811, 9839, 9888,\n",
      "       9905, 9982]),)\n"
     ]
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "from keras.datasets import mnist\n",
    "\n",
    "# loads the MNIST dataset\n",
    "(x_train, y_train), (x_test, y_test)  = mnist.load_data()\n",
    "\n",
    "# Use numpy to create an array that stores a value of 1 when a misclassification occurs\n",
    "result = np.absolute(y_test - y_pred)\n",
    "result_indices = np.nonzero(result > 0)\n",
    "\n",
    "#  Display the indices of mislassifications\n",
    "print(\"Indices of misclassifed data are: \\n\\n\" + str(result_indices))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Displaying the misclassifications"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 \n",
    "#from keras.models import load_model\n",
    "\n",
    "#classifier = load_model('/home/deeplearningcv/DeepLearningCV/Trained Models/mnist_simple_cnn.h5')\n",
    "\n",
    "def draw_test(name, pred, input_im, true_label):\n",
    "    BLACK = [0,0,0]\n",
    "    expanded_image = cv2.copyMakeBorder(input_im, 0, 0, 0, imageL.shape[0]*2 ,cv2.BORDER_CONSTANT,value=BLACK)\n",
    "    expanded_image = cv2.cvtColor(expanded_image, cv2.COLOR_GRAY2BGR)\n",
    "    cv2.putText(expanded_image, str(pred), (152, 70) , cv2.FONT_HERSHEY_COMPLEX_SMALL,4, (0,255,0), 2)\n",
    "    cv2.putText(expanded_image, str(true_label), (250, 70) , cv2.FONT_HERSHEY_COMPLEX_SMALL,4, (0,0,255), 2)\n",
    "    cv2.imshow(name, expanded_image)\n",
    "\n",
    "for i in range(0,10):\n",
    "\n",
    "    input_im = x_test[result_indices[0][i]]\n",
    "    #print(y_test[result_indices[0][i]])\n",
    "    imageL = cv2.resize(input_im, None, fx=4, fy=4, interpolation = cv2.INTER_CUBIC) \n",
    "    input_im = input_im.reshape(1,28,28,1) \n",
    "    \n",
    "    ## Get Prediction\n",
    "    res = str(model.predict_classes(input_im, 1, verbose = 0)[0])\n",
    "    draw_test(\"Prediction\", res, imageL, y_test[result_indices[0][i]]) \n",
    "    cv2.waitKey(0)\n",
    "\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
